<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>利客送社区连锁超市</title>
	<!--[if lte IE 6]><script type="text/javascript" src="__ROOT__/statics/www/scripts/ie6.js"></script> <![endif]-->
	<link rel="apple-touch-icon-precomposed" href="__ROOT__/statics/mobile/images/icon.png"/>
	<link rel="stylesheet" type="text/css" href="__ROOT__/statics/www/css/bootstrap.css"  />
	<link rel="stylesheet" type="text/css" href="__ROOT__/statics/www/css/main_red.css"  />
	<link rel="shortcut icon" href="__ROOT__/statics/www/mobile/favicon.ico">
	<script type="text/javascript" src="__ROOT__/statics/www/scripts/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="__ROOT__/statics/www/scripts/bootstrap.min.js"></script>
	<script type="text/javascript" src="__ROOT__/statics/www/scripts/jquery/jquery.carouFredSel-6.2.1-packed.js"></script>
	
	<!--[if lte IE 9]><script type="text/javascript" src="__ROOT__/statics/www/scripts/ie789.js"></script> <![endif]-->
	<block name="script_header"></block>
</head>
<body>
<block name="top_header">
</block>
<div class="header-line"></div>
<div id="wrap">
	<div class="container">
		<!-- 顶部导航 -->
		<div class="row top" >
			<div class="span10">
				<ul class="nav nav-pills">
					<li><a href="javascript:openChooseShop()" class="area" id="changeArea"><span class="icon icon-map-marker"></span><span id="shopAddress"></span><em>[切换社区]</em></a></li>
				</ul>
			</div>
			<div class="span10">
				<ul class="nav nav-pills pull-right">
					<empty name='Think.session.SES_CUST_ID'>
						<li><a href="{:U('Index/index')}"  id="loginStatus">首页</a></li>
						<li><a href="{:U('CustOrder/index')}"  id="loginStatus">我的订单</a></li>
						<li><a href="{:U('CustPassport/index')}"  id="loginStatus">登录</a></li>
						<li><a href="{:U('CustPassport/showRegist')}"  id="loginStatus">注册</a></li>
					<else/>
						<li><a href="{:U('CustPassport/index')}"  id="loginStatus">您好!{$Think.session.SES_CUST|m_k2v=name}</a></li>
						<li><a href="{:U('Cust/index')}"  id="loginStatus">我的利客送</a></li>
						<li><a href="{:U('CustOrder/index')}"  id="loginStatus">我的订单</a></li>
						<li><a href="{:U('CustPassport/doLogout')}"  id="loginStatus">退出</a></li>
					</empty>
				</ul>
			</div>
		</div>
		<block name="page_header"><include file="Public:header"/></block>
		<block name="page_body"></block>
	</div>
</div>
<block name="page_footer">
	<include file="Public:footer"/>
</block>
<div id="showShop" class="modal hide fade">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			<h3>选择距离您最近的店铺</h3>
	</div>
	<div class="modal-body"></div>
	<div class="modal-footer">
		利客送社区连锁超市服务宗旨：货到付款，当面验货，不满意立刻退！
	</div>
</div>
<block name="script_footer"></block>
<script type="text/javascript">

$(document).ready(function(){
	initShopInfo();
	$('.carousel').carousel();
	<if condition="$isShowShop eq 1">
	openChooseShop();
	</if>
})
function initShopInfo(){
	var shop_info = "{:cookie('COK_SHOP')}";
	if(shop_info!=''){
		var shop_info_ary = shop_info.split("|");
		$("#shopAddress").html(shop_info_ary[2]);
	}else{
		$("#shopAddress").html("{$tempShopAddress}");
	}
}

//写cookies
function setCookie(name,value){
	var Days = 30;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ value + ";expires=" + exp.toGMTString();
}
  
 //读cookie 
 function getCookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)){
		return (arr[2]);
	}else{
		return null;
	}
 }
 
//删除cookies
function delCookie(name){
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null){
    	document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }
}
function redirect(url,isNewWin) {
	var arg0 = (arguments[0]!=undefined) ? arguments[0] : "#"; 
	var arg1 = (arguments[1]!=undefined) ? arguments[1] : false;
	if(arg1){
		window.open(url);
	}else{
		location.href = url;		
	}
}
function addToCart(prod_id,num,edittype,eventObj){
	//问题 直接在底部不加载数据了
	//document.location.href = "/cart/doadd.html?prod_id="+prod_id+"&num="+num+"&edittype="+edittype;
	$(".withTip").popover('destroy');
	$.ajax({
		'async': false, 
        'url': "/cart/doadd.html",
        'dataType': "json",
        'data': {'prod_id':prod_id,'num':num,'edittype':edittype},
        'success': function (data) {
        	if(data['error']=='0'){
            	var cart_num = data['cart_num'];
            	var item_num = data['item_num'];
            	$("#cartNum").html(cart_num);
            	var title = "恭喜您：商品已加入到购物车";
            	var content = "<div class='text-center'><button type='button' class='btn btn-success btn-small' onclick='closeTip()'>再逛逛</button>&nbsp;&nbsp;<button type='button' class='btn btn-danger btn-small'  onclick='showCart()'>去结算</button></div>";
            	if(data['message']!=""){
            		title = data['message'];
            	}
            	
            	$(eventObj).popover({'title':title,'content':content,'html':true,'placement':'bottom',trigger:'manual'});
            	$(eventObj).popover('show');
        	}else{
        		var title = data['message'];
            	var content = "<div class='text-center'><button type='button' class='btn btn-success btn-small' onclick='closeTip()'>再逛逛</button>&nbsp;&nbsp;<button type='button' class='btn btn-danger btn-small'  onclick='showCart()'>去结算</button></div>";
        		$(eventObj).popover({'title':title,'content':content,'html':true,'placement':'bottom',trigger:'manual'});
        		$(eventObj).popover('show');
        	}
        	
        }
    });
}

function closeTip(){
	$(".withTip").popover('destroy');
}
function searchProd(cate){
	location.href = "/product/index/cate_code/"+cate+".html";
}
function searchProdByName(){
	var formObj = document.forms["form_prod_search"];
	formObj.action = "{:U('Product/index')}";
	formObj.submit();
}

function showCart(){
	location.href = "/cart/index.html";
}
//显示更新菜单窗口
function openChooseShop(){
	$.post(
		"{:U('Index/showChgshop')}", 
		{}, 
		function(htmldata){
			$("#showShop .modal-body").html(htmldata);
			$('#showShop').modal('show');
		},
		"html"
	);
}
function chgShop(action_url){
	$.ajax({
        'url': action_url,
        'type':"get",
        'dataType': "json",
        'success': function (data) {
        	var error = data['error'];
        	var message = data['message'];
        	if(error=='0'){
        		document.location.href="/Index/index.html"; 
        	}else{
        		alert(message);
        	}
        }
    });
	return false;
}
</script>
</body>
</html>